//
//  JCVideoApi.m
//  SquashSpark
//
//  Created by Guo.JC on 2017/12/5.
//  Copyright © 2017年 Coollang-YF. All rights reserved.
//

#import "JCVideoApi.h"
#import "YFStarVideoModel.h"
#import "CoachVideo.h"

@implementation JCVideoApi

//获取视频大类列表
+ (JCVideoApi *)getVideoNodesComplete:(void(^)(NSError *error, NSArray <YFStarVideoModel *>*videoNodes)) complete{
    JCVideoApi *videoApi = [JCVideoApi requestApiWithType:kGetVideoStarListApi andParam:nil];
    if ([videoApi loadCacheWithError:nil]) {
        complete(nil, [YFStarVideoModel creatModelArrayWith:[videoApi responseInfo]]);
    }else{
        [[YFNetworkingService sharedInstance] sendRequest:videoApi callback:^(BOOL success, id result, NSError *error) {
            if (success && complete) {
                complete(nil, [YFStarVideoModel creatModelArrayWith:[result responseInfo]]);
            }else if(complete){
                complete(error, nil);
            }
        }];
    }
    return videoApi;
}

//获取视频列表
+ (JCVideoApi *)getNodeVideoListForNodeID:(NSString *)nodeID
                                 complete:(void(^)(NSError *error, NSArray <CoachVideo *>*videoList)) complete{
    NSDictionary *param = @{@"ID":nodeID};
    JCVideoApi *videoApi = [JCVideoApi requestApiWithType:kGetVideoListForIDApi andParam:param];
    if ([videoApi loadCacheWithError:nil]) {
         complete(nil, [CoachVideo creatModelArrayWith:[videoApi responseInfo]]);
    }else {
        [[YFNetworkingService sharedInstance] sendRequest:videoApi callback:^(BOOL success, id result, NSError *error) {
            if (success && complete) {
                complete(nil, [CoachVideo creatModelArrayWith:[result responseInfo]]);
            }else if(complete){
                complete(error, nil);
            }
        }];
    }
    return videoApi;
}

// 设置缓存时间
- (NSInteger)cacheTimeInSeconds {
    if (self.apiType == kGetVideoListForIDApi ||
        self.apiType == kGetVideoStarListApi) {
        return 600;// 10分钟缓存
    }
    return [super cacheTimeInSeconds];
}

@end
